package com.kayt.cyberBar.cuser.business.server.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kayt.cyberBar.cuser.business.dao.ICyberBaseTaskPicDao;
import com.kayt.cyberBar.cuser.business.entity.po.BCyberBaseTaskPic;
import com.kayt.cyberBar.cuser.business.entity.vo.CyberBaseTaskPicVO;
import com.kayt.cyberBar.cuser.business.server.ICyberBaseTaskPicServer;

@Service("iCyberBaseTaskPicServer")
public class CyberBaseTaskPicServerImpl implements ICyberBaseTaskPicServer {
	private static Logger logger = LoggerFactory.getLogger(CyberBaseTaskPicServerImpl.class);
	
	@Autowired
	private ICyberBaseTaskPicDao iCyberBaseTaskPicDao;

	@Override
	public BCyberBaseTaskPic get_pic_by_code(String reportCode) {
		if (reportCode != null) {
			try {
				BCyberBaseTaskPic item = this.iCyberBaseTaskPicDao.getPicByCode(reportCode);
				return item;
			} catch (SQLException e) {
				logger.error("get_pic_by_code with a SQLException", e);
			}
		}
		return null;
	}
	
	@Override
	public CyberBaseTaskPicVO assemble_vo(BCyberBaseTaskPic item) {
		if (item != null) {
			CyberBaseTaskPicVO vo = new CyberBaseTaskPicVO();
			vo.setCode(item.getCode());
			vo.setCreateTime(item.getCode());
			String id = item.getId() == null ? null : item.getId().toString();
			vo.setId(id);
			vo.setPicUrl(item.getPicUrl());
			vo.setReportCode(item.getReportCode());
			vo.setSequnce(item.getSequnce());
			vo.setUpdateTime(item.getUpdateTime());
			return vo;
		}
		return null;
	}
	
	@Override
	public List<CyberBaseTaskPicVO> assemble_vo_list (List<BCyberBaseTaskPic> itemList) {
		List<CyberBaseTaskPicVO> voList = new ArrayList<>();
		if (itemList != null && !itemList.isEmpty()) {
			for (BCyberBaseTaskPic item : itemList) {
				CyberBaseTaskPicVO vo = this.assemble_vo(item);
				voList.add(vo);
			}
		}
		return voList;
	}
}
